home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++,comp.os.linux.development.apps,comp.os.linux.misc
- Path: indra.com!!bear
- From: bear@ (Bear Giles)
- Subject: Re: Are str* functions okay in C++?
- Message-ID: <Do54G9.4Ly.0.server@indra.com>
- Sender: usenet@indra.com (System Operator)
- Organization: I need to put my ORGANIZATION here.
- Date: Tue, 12 Mar 1996 05:55:20 GMT
- References: <4hpvi0$gt6@news.platinum.com>
- X-Nntp-Posting-Host: net.indra.com
-
- In article <4hpvi0$gt6@news.platinum.com>,
- Mark Juric <dcmark@platinum.com> wrote:
- > path = new char[strlen(mbuf)+1];
- > strcpy(path,mbuf);
-
- One quick note: there's a "strdup()" function which handles this
- for you, although it uses "free" instead of "delete."
-
- Also, another useful technique for this type of code is:
-
- void procedure (argument...)
- {
- static char * buffer = 0;
-
- if (buffer == 0)
- buffer = malloc (2048); /* or any _large_ number */
-
- ...
- sprintf (buffer, format,...)
- path = strdup (buffer);
- ...
-
- The idea is that "buffer" is a captive memory leak -- you allocate a
- large buffer once and never release it. That increases the runtime
- size of your program, but eliminates the performance hit and possible
- memory leaks from repeatedly allocating and deleting small blocks.
-
-